<?php
/**
 * Created by PhpStorm.
 * User: tc-net modify by tom_xia
 * Date: 2018/3/14 0014
 * Time: 10:29
 */
require_once dirname(__DIR__) . "/common.php";
use app\cls\tom\Queue;
use app\cls\tom\Response;
use app\cls\tom\SysResource;
use app\cls\tom\Tools;
use app\cls\tom\Visitor;

$host = @parse_url(isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:"",PHP_URL_HOST);
$visitor = new Visitor();
$visitorInfo = $visitor->getVisitorId();
$d['xm'] = isset($_POST['xm']) ? trim($_POST['xm']) : 'host';  //项目
$d['op'] = isset($_POST['op']) ? trim($_POST['op']) : 'pv';   //pv 还是share
$d['wz'] = isset($_POST['wz']) ? trim($_POST['wz']) : '';        //位置
$d['pt'] = isset($_POST['xm']) ? trim($_POST['xm']) : 'h5';    //平台 h5 web
$d['uniqueid'] =  isset($_POST['uniqueid']) && $_POST["uniqueid"] != "undefined" ? trim($_POST['uniqueid']) : "";
$d['other'] = isset($_POST['other']) ? trim($_POST['other']) : '';
$d['uid'] = isset($_POST['vir_ID']) ? trim($_POST['vir_ID']) : $visitorInfo[1];
$d['ip'] = explode(",",Tools::get_client_ip())[0];
$d['id'] = isset($_POST['id']) ? $_POST['id'] : '';
$d['source'] = isset($_POST['source']) ? $_POST['source'] : '';
$d['time'] = date("Y-m-d H:i:s");


$suffix=rand(1,5);
//正式key
//$key = REDIS_PREFIX."PV_".$suffix;//这是入统计队列的key
//$ugc_key=REDIS_PREFIX."ugc_statics_".$suffix;//这是入user_material表的分享统计
//$material_key=REDIS_PREFIX."material_statics_".$suffix;//这是入video表的分享统计
//测试key
$key = REDIS_PREFIX."test_PV_".$suffix;//这是入统计队列的key
$ugc_key=REDIS_PREFIX."test_ugc_statics_".$suffix;//这是入user_material表的分享统计
$material_key=REDIS_PREFIX."test_material_statics_".$suffix;//这是入video表的分享统计

//开始入队列
if($d['xm']&&$d['uid']){
    $redis = SysResource::getRedis();
    //1.把ugc的分享入队列
    if(!empty($d['uniqueid']) && !empty($d['id']) && $d['source']=="ugc" && $d['op']=="share"){
        $redis->lPush($ugc_key,json_encode($d));
    }
    //2.把配音（material）的分享入队列
    if(!empty($d['uniqueid']) && !empty($d['id']) && $d['source']=="material" && $d['op']=="share"){
        $redis->lPush($material_key,json_encode($d));
    }
    //把统计数据入库
    $redis->lPush($key,json_encode($d));
    Response::output(0,"ok",["vir_ID"=>$visitorInfo[1]]);
}else{
    Response::output(-1,"fail",["vir_ID"=>$visitorInfo[1]]);
}

